package com.kyxx.mycommonproject.shangpinfenlei;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.kyxx.mycommonproject.R;
import com.kyxx.mycommonproject.base.BaseActivity0;
import com.kyxx.mycommonproject.wodedingdan.GoodClassFragment;
import com.kyxx.mycommonproject.wodedingdan.TabFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

public class GoodClassActivity extends BaseActivity0 {
    private TabLayout tl;
    private ViewPager vp;
    private String[] titles = new String[]{"为您推荐", "食品", "手机数码", "家装", "游戏动漫", "女装", "男装", "鞋靴", "箱包"};

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_good_class);
    }

    @Override
    protected void findViewById() {
        tl = (TabLayout) findViewById(R.id.tl);
        vp = (ViewPager) findViewById(R.id.vp);
    }

    @Override
    protected void setListener() {
    }

    @Override
    protected void processLogic() {
        loadToolBar("商品分类");
        List<Fragment> fragments = new ArrayList<Fragment>();
        for (int i = 0; i < titles.length; i++) {
            GoodClassFragment myGoodClassFragment = new GoodClassFragment();
            myGoodClassFragment.setKey(titles[i]);
            fragments.add(myGoodClassFragment);
        }
        vp.setAdapter(new TabFragmentAdapter(fragments, titles, getSupportFragmentManager(), context));
        tl.setupWithViewPager(vp);
        tl.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vp.setCurrentItem(tab.getPosition(), false);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
}
